package cn.wp.ewallet.common.dao.impl;

import cn.wp.common.core.dao.JdbcSupportTemplate;
import cn.wp.common.core.dao.SqlString;
import cn.wp.ewallet.common.dao.DocContentDao;
import cn.wp.ewallet.common.extension.constant.EwalletConstant;
import cn.wp.ewallet.common.model.entity.DocContentDo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 文档内容-数据访问层实现
 * Created by ganjie on 2020/01/08
 */
@Repository
public class DocContentDaoImpl implements DocContentDao {

    @Autowired
    private JdbcSupportTemplate jdbcSupportTemplate;

    @Override
    public DocContentDo selectServiceInfoListByType(String docId, String langCode) {
        SqlString sqlString = SqlString.newInstance();
        sqlString.add("select a.DOC_CONTENT");
        sqlString.add("from doc_content a");
        sqlString.add("    left join pub_language_info b on a.KEY_ID = b.KEY_ID");
        sqlString.add("where b.LANG_CODE = ?");
        sqlString.add("    and a.DOC_ID = ?");
        sqlString.add("    and a.`STATUS` = ?");
        sqlString.add("    and b.IS_SHOW = ?");
        Object[]params=new Object[]{
                langCode,
                docId,
                EwalletConstant.STATUS,
                EwalletConstant.STATUS
        };
        return jdbcSupportTemplate.selectObject(sqlString.build(), params, DocContentDo.class);
    }

    @Override
    public List<DocContentDo> selectFinaProdInfoRoleByfinaProdId(String finaProdId, String langCode) {
        SqlString sqlString = SqlString.newInstance();
        sqlString.add("select c.SHOW_NAME DOC_CONTENT");
        sqlString.add("from OBJ_DOC_REL a, DOC_CONTENT b,KEY_LANGUGE_REL c");
        sqlString.add("where a.DOC_ID = b.DOC_ID");
        sqlString.add("    and b.KEY_ID = c.KEY_ID");
        sqlString.add("    and a.OBJ_ID = ?");
        sqlString.add("    and a.status = ?");
        sqlString.add("    and b.status= ?");
        sqlString.add("    and c.LANG_CODE = ?");
        return jdbcSupportTemplate.selectList(sqlString.build(), new Object[]{finaProdId, EwalletConstant.STATUS,EwalletConstant.STATUS,langCode}, DocContentDo.class);
    }
}


